package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by malliks on 25/02/14.
 */
public class Registry {

    List<String> booklist = new ArrayList<String>();
    List<Movie> movielist=new ArrayList<Movie>();
    List checkedoutbooks=new ArrayList<String>();

    Customer customer=new Customer();

    public Registry()
    {
        booklist.addAll(Arrays.asList("book1", "book2", "book3"));
        movielist.add(new Movie("movie1","1990","director",5));
        movielist.add(new Movie("movie2","2000","director",7));
    }

    public List<String> getBooklist()
    {
        return booklist;
    }



    public boolean checkOutBook(String bookname)
    {
        if(booklist.remove(bookname))
        {
            checkedoutbooks.add(bookname);
        customer.addToCheckedOutBook(bookname);

                return true;
        }

        return false;
    }

    public boolean  isCheckedOut(String bookname)
    {

        return checkedoutbooks.contains(bookname);


    }

    public void addBook(String bookname)
    {
        booklist.add(bookname);
    }

    public boolean returnBook(String bookname)

    {
        if(isCheckedOut(bookname))
        {
            addBook(bookname);

           if(checkedoutbooks.remove(bookname) ){
               customer.removeFromCheckedOutBookList(bookname);
            return true;
           }
            else
               return false;
        }
        else
        {
            return false;

        }


    }

    public List<Movie> getMovielist() {
        return movielist;
    }

    public boolean checkOutMovie(String moviename)
    {
        for(Movie list:getMovielist())
        {
            if(list.getName().equalsIgnoreCase(moviename))
            {
                movielist.remove(list);
                return true;
            }

        }

        return false;
    }

    public boolean authentication(String library_number, String password)
    {
       if(customer.getLibrary_number().equals(library_number))
       if(customer.getPassword().equals(password))
       {
           return true;
       }
        return false;
    }


}
